﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AtletIS.Shared.WpfControls
{
    /// <summary>
    /// Interaction logic for ChipViewerBox.xaml
    /// </summary>
    public partial class ChipViewerBox : UserControl
    {
        public ChipViewerBox(int nOrder, int nStartNumber, string sCountry, string sName, string sResult, string[] aExtTexts)
        {
            InitializeComponent();

            if (nOrder == 0)
                txtOrder.Text = string.Empty;
            else
                txtOrder.Text = nOrder.ToString();

            string sFilePath = AppDomain.CurrentDomain.BaseDirectory;
            sFilePath = System.IO.Path.Combine(sFilePath, "Ext", "Flags", "24px", sCountry + ".png");
            if (System.IO.File.Exists(sFilePath))
            {
                BitmapImage flag = new BitmapImage();
                flag.BeginInit();
                flag.UriSource = new Uri(sFilePath);
                flag.EndInit();
                iCountry.Source = flag;
            }

            if (nStartNumber == 0)
                txtStartNumber.Text = string.Empty;
            else
                txtStartNumber.Text = "(" + nStartNumber.ToString() + ")";

            txtName.Text = sName;
            txtResult.Text = sResult;

            // Penalties
            borPen1.Visibility = System.Windows.Visibility.Hidden;
            borPen2.Visibility = System.Windows.Visibility.Hidden;
            borPen3.Visibility = System.Windows.Visibility.Hidden;
            borPen4.Visibility = System.Windows.Visibility.Hidden;

            if (aExtTexts != null)
            {
                for (int i = 0; i < aExtTexts.Length; i++)
                {
                    if (i == 0)
                    {
                        borPen1.Visibility = System.Windows.Visibility.Visible;
                        if (aExtTexts[i] == "PB" | aExtTexts[i] == "SB")
                        {
                            txtPen1.Text = aExtTexts[i];
                            txtPen1.FontSize = 12;
                        }
                        else
                            txtPen1.Text = aExtTexts[i].Substring(0, 1);
                    }

                    if (i == 1)
                    {
                        borPen2.Visibility = System.Windows.Visibility.Visible;
                        txtPen2.Text = aExtTexts[i].Substring(0, 1);
                    }

                    if (i == 2)
                    {
                        borPen3.Visibility = System.Windows.Visibility.Visible;
                        txtPen3.Text = aExtTexts[i].Substring(0, 1);
                    }

                    if (i == 3)
                    {
                        borPen4.Visibility = System.Windows.Visibility.Visible;
                        txtPen4.Text = aExtTexts[i].Substring(0, 1);
                    }
                }
            }
        }
    }
}
